package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSave;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Size;
import java.util.List;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/v1/dictoption")
public class DictOptionController {
    @Autowired
    DictOptionService dictOptionService;

    @GetMapping("select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery) {
        log.debug("查询字典项:dictOptionQuery={}", dictOptionQuery);
        List<DictOptionVO> list = dictOptionService.selectDictOption(dictOptionQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveDictOption(DictOptionSave dictOptionSave) {
        log.debug("保存字典项:dictOptionSave={}", dictOptionSave);
        dictOptionService.saveDictOption(dictOptionSave);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id) {
        log.debug("删除字典项:id={}", id);
        dictOptionService.deleteDictOption(id);
        return JsonResult.ok();
    }
    /**
     * 定义一个根据字典code查询字典项的接口
     * */
    @GetMapping("select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code) {
        log.debug("根据字典code查询字典项:code={}", code);
        List<DictOptionVO> list = dictOptionService.selectDictOptionByCode(code);

        return JsonResult.ok(list);
    }

}










